package com.ruoyi.web.controller.tool;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bnt.domain.BntSundayworship;
import com.ruoyi.bnt.domain.BntWorshipinfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * swagger 百年堂小程序接口
 * 
 * @author yyj
 */
@Api("获取主日模块数据")
@RestController
@RequestMapping("/bnt/api/sundayworship")
public class SundayWorshipController extends BaseController
{
    @Autowired
    private com.ruoyi.bnt.service.IBntSundayworshipService bntSundayworshipService;
    @Autowired
    private com.ruoyi.bnt.service.IBntWorshipinfoService bntWorshipinfoService;

    @ApiOperation("获取主日列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前显示页数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "beginWorshipDate", value = "敬拜日期过滤（>=）", required = false, dataType = "date", paramType = "query")
    })
    @GetMapping("/list")
    public TableDataInfo list(int pageSize,int pageNum,Date beginWorshipDate)
    {
        com.ruoyi.bnt.domain.BntSundayworship bntSundayworship =  new BntSundayworship();
        if(beginWorshipDate != null){
            bntSundayworship.setWoshipDate(beginWorshipDate);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<com.ruoyi.bnt.domain.BntSundayworship> list = bntSundayworshipService.selectBntSundayworshipList(bntSundayworship);
        return getDataTable(list);
    }

    @ApiOperation("根据获取主日详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主日记录id", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/info")
    public BntSundayEntity info(String id)
    {
        BntSundayEntity bntSundayEntity = new BntSundayEntity();
        com.ruoyi.bnt.domain.BntSundayworship bntSundayworship =  new BntSundayworship();
        bntSundayworship.setId(id);
        List<com.ruoyi.bnt.domain.BntSundayworship> list = bntSundayworshipService.selectBntSundayworshipList(bntSundayworship);
        if(list.size() > 0){
            bntSundayEntity.setBntSundayworship(list.get(0));
            BntWorshipinfo bntWorshipinfo =  new BntWorshipinfo();
            bntWorshipinfo.setParentId(id);
            bntWorshipinfo.setInfoType("1");
            List<BntWorshipinfo> listXY = bntWorshipinfoService.selectBntWorshipinfoList(bntWorshipinfo);
            bntSundayEntity.setBntWorshipinfoXY(listXY);
            bntWorshipinfo.setInfoType("2");
            List<BntWorshipinfo> listHY = bntWorshipinfoService.selectBntWorshipinfoList(bntWorshipinfo);
            bntSundayEntity.setBntWorshipinfoHY(listHY);
        }
        //访问量加一
        bntSundayworshipService.addVisitNum(id);
        return bntSundayEntity;
    }
}

@ApiModel("主日详情实体")
class BntSundayEntity
{
    @ApiModelProperty("主体")
    private BntSundayworship bntSundayworship;

    @ApiModelProperty("序乐")
    private List<com.ruoyi.bnt.domain.BntWorshipinfo> bntWorshipinfoXY;

    @ApiModelProperty("回应")
    private List<com.ruoyi.bnt.domain.BntWorshipinfo> bntWorshipinfoHY;

    public BntSundayworship getBntSundayworship() {
        return bntSundayworship;
    }

    public void setBntSundayworship(BntSundayworship bntSundayworship) {
        this.bntSundayworship = bntSundayworship;
    }

    public List<BntWorshipinfo> getBntWorshipinfoXY() {
        return bntWorshipinfoXY;
    }

    public void setBntWorshipinfoXY(List<BntWorshipinfo> bntWorshipinfoXY) {
        this.bntWorshipinfoXY = bntWorshipinfoXY;
    }

    public List<BntWorshipinfo> getBntWorshipinfoHY() {
        return bntWorshipinfoHY;
    }

    public void setBntWorshipinfoHY(List<BntWorshipinfo> bntWorshipinfoHY) {
        this.bntWorshipinfoHY = bntWorshipinfoHY;
    }
}
